package com.copa.l136;

/**
 * @author copa
 * @createDate 2022-08-03 18:23
 * @function 位运算（异或方法）
 */
public class Test1 {

    public int singleNumber(int[] nums) {
        if (nums.length == 1) {
            return nums[0];
        }
        int result = 0;
        for (int i = 0; i < nums.length; i++) {
            // 异或运算
            result ^= nums[i];
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {4,1,2,1,2};
        System.out.println(new Test1().singleNumber(nums));
    }
}
